
import Api_parse360, {baseURL} from "./api_parse360";
export default function ({ redirect, app, app: {$axios}}, inject)  {
  $axios.defaults.baseURL = baseURL; // 默认地址
  $axios.defaults.timeout = 20 * 1000;
  $axios.defaults.headers = {
    ["content-type"]:  "application/json"
  }
  const API_parse360 = new Api_parse360({$axios});
  app.$api_parse360 = API_parse360;
  inject('api_parse360', API_parse360)
  $axios.onRequest(config => {

  });

  $axios.interceptors.response.use(response => {
    if(response.data.status === 200) {}
    return Promise.resolve(response.data)
  },error => {
    if(error.response.status === 500){
      // http状态500，服务器内部错误，重定向到500页面
      redirect("/500")
    }
    if(error.response.status === 404){
      // http状态500，请求API找不到，重定向到404页面
      redirect("/404")
    }
    return Promise.reject(error.response)
  })


  $axios.onError(config => {
    console.log('Making request to ' + config.url)
  })
};



